package mytest.ssw.www.myandroidproject.net;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Objects;
import java.util.Scanner;

/**
 * Created by 73409 on 2015/10/25.
 */
public class MyPOST {

    public  String  DoPOST(String urls,String value)
    {
        String restring=null;
        try {
            URL url = new URL(value);
            HttpURLConnection conn =  (HttpURLConnection)url.openConnection();
            conn.setConnectTimeout(6*1000);
            if (conn.getResponseCode()==200)
            {
                InputStream is = conn.getInputStream();
                Scanner scanner = new Scanner(is, "UTF-8");
                restring = scanner.useDelimiter("\\A").next();
                scanner.close();
                Log.v("str", restring);
            }

        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
           return restring;
    }
public String DoPOST(String urls,String value,String more)
    {
        return null;
    }



    public Object DoPOSTImage(String imageurl)
    {
        Bitmap bitmap=null;
        try {
            URL url = new URL(imageurl);
            HttpURLConnection conn =  (HttpURLConnection)url.openConnection();
            conn.setConnectTimeout(6*1000);
            if (conn.getResponseCode()==200)
            {
                InputStream is = conn.getInputStream();
                bitmap = BitmapFactory.decodeStream(is);
                is.close();
            }

        } catch (MalformedURLException e) {
            bitmap=null;
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
            bitmap=null;
        }
        return bitmap;
    }
    public String SmPost(String urlstr)
    {
        String restring=null;
        try {
            URL url = new URL(urlstr);
            HttpURLConnection conn =  (HttpURLConnection)url.openConnection();
            conn.setConnectTimeout(3*1000);
            if (conn.getResponseCode()==200)
            {
                InputStream is = conn.getInputStream();
                Scanner scanner = new Scanner(is, "UTF-8");
                restring = scanner.useDelimiter("\\A").next();
                scanner.close();
            }

        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return restring;
    }

}
